import { ControlServiceBase } from '@ibiz-core';
import { BookService } from '@service';
import { ControlVO } from './control-config';

export class ControlService extends ControlServiceBase {
  /**
   * 实体服务对象
   */
  public entityService: BookService = new BookService();

  /**
   * 加载数据
   *
   * @param [context={}] 上下文参数
   * @param [data={}] 视图参数
   * @param opts
   * @return {*}
   */
  public async get(context: any, data: any, opts: { action: string; isLoading?: boolean }): Promise<any> {
      const { context: Context, data: Data } = this.handleRequestData(context, data, opts);
      let response: any;
      const _entityService: any = this.entityService;
      if (_entityService[opts.action] && _entityService[opts.action] instanceof Function) {
        response = await _entityService[opts.action](Context, Data, opts.isLoading);
      } else {
        response = await this.entityService.Get(Context, Data, opts.isLoading);
      }
      // this.setRemoteCopyData(response);
      response.data = new ControlVO(response.data);
      return this.handleResponse(response, opts);
    }
    
  }
